FENNEL = /usr/bin/fennel
LUASTATIC = /usr/bin/luastatic
LIB_LUA_STATIC = /usr/lib/liblua.a
LUA_INCLUDE = /usr/include/
ARCH := $(shell uname -m)

all: config qire.lua qire
.PHONY: all

qire.lua: qire.fnl
	$(FENNEL) --compile qire.fnl > qire.lua

config: base-config
	cp base-config config
	echo "repo dragora-$(ARCH) http://rsync.dragora.org/testing/packages/$(ARCH)/" >> config

# on macOS: $(LUASTATIC) qire.lua str.lua list.lua iteration.lua tbl.lua -llua5.3 -I/usr/local/include/lua5.3
qire: base-config qire.lua
	$(LUASTATIC) qire.lua $(LIB_LUA_STATIC) -I$(LUA_INCLUDE) -static

install: config qire
	mkdir -p $(DESTDIR)/var
	mkdir -p $(DESTDIR)/var/cache
	mkdir -p $(DESTDIR)/var/cache/qire
	mkdir -p $(DESTDIR)$(PREFIX)/bin
	cp -f qire $(DESTDIR)$(PREFIX)/bin
	chmod 755 $(DESTDIR)$(PREFIX)/bin/qire
	mkdir -p $(DESTDIR)/etc
	mkdir -p $(DESTDIR)/etc/qire
	cp -f config $(DESTDIR)/etc/qire/qirerc

uninstall:
	rm -f $(DESTDIR)$(PREFIX)/bin/qire
	rm -rf $(DESTDIR)/etc/qire

clean:
	rm config qire.lua qire
